public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode head;
    public ListNode tail;

    //尾插法
    public void offer(int val) {
        ListNode node=new ListNode(val);
        if(head==null) {
            head=tail=node;
        }else {
            tail.next=node;
            node.prev=tail;
            tail=node;
        }
    }

    public int poll() {
        if(head==null) return -1;
        int ret=head.val;
        if(head.next==null) {
            head=null;
            tail=null;
        }else {
            head=head.next;
            head.prev=null;
        }
        return ret;
    }

    public int peek() {
        if(head==null) return -1;
        return head.val;
    }

    public boolean isEmpty() {
        return head==null;
    }

}
